package com.canaan.business.controller.pc.api.erp;

import cn.hutool.json.JSONUtil;
import com.canaan.common.encrypt.BaseReqParam;
import com.canaan.common.encrypt.HttpRequestDecodeFilter;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class HttpCommonReq {
    public BaseReqParam getCommonReq(HttpServletRequest request) {
        if (request instanceof HttpRequestDecodeFilter.DecodeHttpServletRequestWrapper) {
            String requestBody = ((HttpRequestDecodeFilter.DecodeHttpServletRequestWrapper) request).getRequestBody();
            BaseReqParam baseReq = JSONUtil.toBean(requestBody, BaseReqParam.class);
            baseReq.setRequestSource(request.getParameter("cid"));
            return baseReq;
        }
        return null;
    }
}
